<template>
  <div class="table">
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      :height="height"
      @selection-change="handleSelectionChange"
      :tree-props="{ children: treeProps }"
      row-key="id"
      :header-cell-style="{ color: '#333333' }"
    >
      <el-table-column
        type="index"
        width="100"
        align="center"
        v-if="isIndex"
        label="序号"
      >
      </el-table-column>

      <el-table-column
        type="selection"
        width="45"
        v-if="isCheckout"
      ></el-table-column>

      <el-table-column
        v-for="(item, index) in listData"
        :key="index"
        :prop="item.prop"
        :label="item.label"
        :width="item.width"
        :align="columnText"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <slot :name="item.prop" :row="scope.row">
            {{ scope.row[item.prop] }}
          </slot>
        </template>
      </el-table-column>

      <el-table-column label="操作" v-if="isOpeation">
        <template slot-scope="scope">
          <slot name="opeartion" :row="scope.row"></slot>
        </template>
        >
      </el-table-column>
    </el-table>

    <el-pagination
      v-if="isPagination"
      style="padding: 10px 0 10px 20px; background-color: #fff"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.current"
      :page-sizes="[1, 5, 10, 50]"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    tableData: {
      type: Array,
      required: true,
    },
    listData: {
      type: Array,
      required: true,
    },
    isOpeation: {
      type: Boolean,
      default: true,
    },
    isCheckout: {
      type: Boolean,
      default: false,
    },
    isIndex: {
      type: Boolean,
      default: false,
    },
    isPagination: {
      type: Boolean,
      default: true,
    },
    page: {
      type: Object,
      default: () => ({ current: 0, pageSize: 1, total: 0 }),
    },
    treeProps: {
      type: String,
      default: "",
    },
    columnText: {
      type: String,
      default: "center",
    },
    height: {
      type: String,
      default: "735",
    },
  },
  methods: {
    handleSizeChange(val) {
      this.$emit("pageSize", val);
    },
    handleCurrentChange(val) {
      this.$emit("currentPage", val);
    },
    handleSelectionChange(val) {
      this.$emit("select", val);
    },
  },
};
</script>

<style scoped lang="less">
.el-table {
  font-size: 14px;
}
</style>
